package com.zfsoft.zfoa.onduty.reliefrequest.dao;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Vector;
import com.zfsoft.zfoa.dao.BasicDAO;
import com.zfsoft.zfoa.onduty.reliefrequest.entitys.Reliefrequest;
public class ReliefrequestDAO extends BasicDAO {
	public Reliefrequest getInstance(String bh) {
		Reliefrequest reliefrequest = new Reliefrequest();
		try {
			String sql = "select * from reliefrequest where id=?";
			conn = this.getConn();
			ps = conn.prepareStatement(sql);
			ps.setString(1, bh);
			rs = ps.executeQuery();
			if (rs.next()) {
				reliefrequest.setId(rs.getString("id"));
				reliefrequest.setArrangementid(rs.getString("arrangementid"));
				reliefrequest.setOriginaldate(rs.getString("originaldate"));
				reliefrequest.setAfterdate(rs.getString("afterdate"));
				reliefrequest.setTimesectid(rs.getString("timesectid"));
				reliefrequest.setTimesectname(rs.getString("timesectname"));
				reliefrequest.setProposerid(rs.getString("proposerid"));
				reliefrequest.setProposername(rs.getString("proposername"));
				reliefrequest.setState(rs.getString("state"));
				reliefrequest.setTime(rs.getString("time"));
				reliefrequest.setPasstime(rs.getString("passtime"));
				reliefrequest.setUserid(rs.getString("userid"));
			}
			closeStmt();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			closeConn();
		}
		return reliefrequest;
	}
	public Boolean update(String bh, Reliefrequest reliefrequest) {
		Boolean res = true;
		String sql = "";
		try {
			sql = "UPDATE reliefrequest SET id=?,arrangementid=?,originaldate=?,afterdate=?,timesectid=?,timesectname=?,proposerid=?,proposername=?,state=?,time=?,passtime=?,userid=? WHERE id=?";
			conn = this.getConn();
			conn.setAutoCommit(false);
			ps = conn.prepareStatement(sql);
			ps.setString(1, reliefrequest.getId());
			ps.setString(2, reliefrequest.getArrangementid());
			ps.setString(3, reliefrequest.getOriginaldate());
			ps.setString(4, reliefrequest.getAfterdate());
			ps.setString(5, reliefrequest.getTimesectid());
			ps.setString(6, reliefrequest.getTimesectname());
			ps.setString(7, reliefrequest.getProposerid());
			ps.setString(8, reliefrequest.getProposername());
			ps.setString(9, reliefrequest.getState());
			ps.setString(10, reliefrequest.getTime());
			ps.setString(11, reliefrequest.getPasstime());
			ps.setString(12, reliefrequest.getUserid());
			ps.setString(13, bh);
			ps.executeUpdate();
			closeStmt();
		} catch (SQLException e) {
			System.out.println(sql);
			e.printStackTrace();
			try {
				conn.rollback();
			} catch (SQLException e1) {
				System.out.println(sql);
				e1.printStackTrace();
			}
			res = false;
		} finally {
			try {
				conn.commit();
			} catch (SQLException e) {
				System.out.println(sql);
				e.printStackTrace();
			}
			closeConn();
		}
		return res;
	}
	public Boolean insert(Reliefrequest reliefrequest) {
		Boolean res = true;
		String sql = "";
		try {
			sql = "insert into reliefrequest(id,arrangementid,originaldate,afterdate,timesectid,timesectname,proposerid,proposername,state,time,passtime,userid) values(?,?,?,?,?,?,?,?,?,?,?,?)";
			conn = this.getConn();
			conn.setAutoCommit(false);
			ps = conn.prepareStatement(sql);
			ps.setString(1, reliefrequest.getId());
			ps.setString(2, reliefrequest.getArrangementid());
			ps.setString(3, reliefrequest.getOriginaldate());
			ps.setString(4, reliefrequest.getAfterdate());
			ps.setString(5, reliefrequest.getTimesectid());
			ps.setString(6, reliefrequest.getTimesectname());
			ps.setString(7, reliefrequest.getProposerid());
			ps.setString(8, reliefrequest.getProposername());
			ps.setString(9, reliefrequest.getState());
			ps.setString(10, reliefrequest.getTime());
			ps.setString(11, reliefrequest.getPasstime());
			ps.setString(12, reliefrequest.getUserid());
			ps.executeUpdate();
			closeStmt();
		} catch (SQLException e) {
			System.out.println(sql);
			e.printStackTrace();
			try {
				conn.rollback();
			} catch (SQLException e1) {
				System.out.println(sql);
				e1.printStackTrace();
			}
			res = false;
		} finally {
			try {
				conn.commit();
			} catch (SQLException e) {
				System.out.println(sql);
				e.printStackTrace();
			}
			closeConn();
		}
		return res;
	}
	
	
	
	
	
}